So registry preloading was added[1] to avoid updating the root path
multiple times unnecessarily, since that's an expensive operation. But
with Package::from_path, we can get the root package just from a
manifest and a config without having to update the whole path source.
So now we don't have to remember to preload the registry if we've
already updated a source and want to use the registry later. Instead, we
just avoid loading the source initially and let the registry do it when
it needs to -- which is now in resolve_with_previous.
This does cause one tested error message to happen slightly later than
it used to, but it still happens.
[1] -
ef8c651af
Ok(())
}
- pub fn preload(&mut self, id: &SourceId, source: Box<Source + 'cfg>) {
- self.sources.insert(id, source);
- self.source_ids.insert(id.clone(), (id.clone(), Kind::Locked));
- }
-
pub fn add_sources(&mut self, ids: &[SourceId]) -> CargoResult<()> {
for id in ids.iter() {
try!(self.load(id, Kind::Locked));
use core::{Profile, TargetKind};
use core::resolver::Method;
use ops::{self, BuildOutput, ExecEngine};
-use sources::{PathSource};
use util::config::{ConfigValue, Config};
use util::{CargoResult, internal, human, ChainError, profile};
-> CargoResult<ops::Compilation<'a>> {
debug!("compile; manifest-path={}", manifest_path.display());
- let mut source = try!(PathSource::for_path(manifest_path.parent().unwrap(),
- options.config));
- // TODO: Move this into PathSource
- let package = try!(source.root_package());
+ let package = try!(Package::for_path(manifest_path, options.config));
debug!("loaded package; package={}", package);
for key in package.manifest().warnings().iter() {
try!(options.config.shell().warn(key))
}
- compile_pkg(&package, Some(Box::new(source)), options)
+ compile_pkg(&package, options)
}
pub fn compile_pkg<'a>(package: &Package,
- source: Option<Box<Source + 'a>>,
options: &CompileOptions<'a>)
-> CargoResult<ops::Compilation<'a>> {
let CompileOptions { config, jobs, target, spec, features,
let (packages, resolve_with_overrides, sources) = {
let mut registry = PackageRegistry::new(config);
- if let Some(source) = source {
- registry.preload(package.package_id().source_id(), source);
- } else {
- try!(registry.add_sources(&[package.package_id().source_id()
- .clone()]));
- }
// First, resolve the package's *listed* dependencies, as well as
// downloading and updating all remotes and such.
use std::path::Path;
use core::registry::PackageRegistry;
-use core::{Source, PackageId};
+use core::{Package, PackageId};
use ops;
-use sources::PathSource;
use util::{CargoResult, Config, human, ChainError};
/// Executes `cargo fetch`.
pub fn fetch(manifest_path: &Path, config: &Config) -> CargoResult<()> {
- let mut source = try!(PathSource::for_path(manifest_path.parent().unwrap(),
- config));
- let package = try!(source.root_package());
-
+ let package = try!(Package::for_path(manifest_path, config));
let mut registry = PackageRegistry::new(config);
- registry.preload(package.package_id().source_id(), Box::new(source));
let resolve = try!(ops::resolve_pkg(&mut registry, &package));
let ids: Vec<PackageId> = resolve.iter().cloned().collect();
use core::PackageId;
use core::registry::PackageRegistry;
-use core::{Resolve, SourceId};
+use core::{Resolve, SourceId, Package};
use core::resolver::Method;
use ops;
-use sources::{PathSource};
use util::config::{Config};
use util::{CargoResult, human};
pub fn generate_lockfile(manifest_path: &Path, config: &Config)
-> CargoResult<()> {
- let mut source = try!(PathSource::for_path(manifest_path.parent().unwrap(),
- config));
- let package = try!(source.root_package());
+ let package = try!(Package::for_path(manifest_path, config));
let mut registry = PackageRegistry::new(config);
- registry.preload(package.package_id().source_id(), Box::new(source));
let resolve = try!(ops::resolve_with_previous(&mut registry, &package,
Method::Everything,
None, None));
pub fn update_lockfile(manifest_path: &Path,
opts: &UpdateOptions) -> CargoResult<()> {
- let mut source = try!(PathSource::for_path(manifest_path.parent().unwrap(),
- opts.config));
- let package = try!(source.root_package());
+ let package = try!(Package::for_path(manifest_path, opts.config));
let previous_resolve = match try!(ops::load_pkg_lockfile(&package)) {
Some(resolve) => resolve,
None => to_avoid.extend(previous_resolve.iter()),
}
- registry.preload(package.package_id().source_id(), Box::new(source));
let resolve = try!(ops::resolve_with_previous(&mut registry,
&package,
Method::Everything,
let new_pkg = Package::new(new_manifest, &manifest_path);
// Now that we've rewritten all our path dependencies, compile it!
- try!(ops::compile_pkg(&new_pkg, None, &ops::CompileOptions {
+ try!(ops::compile_pkg(&new_pkg, &ops::CompileOptions {
config: config,
jobs: None,
target: None,
to_avoid: Option<&HashSet<&'a PackageId>>)
-> CargoResult<Resolve> {
+ try!(registry.add_sources(&[package.package_id().source_id()
+ .clone()]));
+
// Here we place an artificial limitation that all non-registry sources
// cannot be locked at more than one revision. This means that if a git
// repository provides more than one package, they must all be updated in
assert_that(p.cargo_process("build"),
execs()
.with_status(101)
- .with_stderr(&format!("Could not find `Cargo.toml` in `{}`\n",
- p.root().join("src").join("bar").display())));
+ .with_stderr(&format!("\
+Unable to update file://[..]
+
+Caused by:
+ Could not find `Cargo.toml` in `{}`
+", p.root().join("src").join("bar").display())));
});